# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: xguo

from coin.exchange.base.kr_rest.currency import NativeCurrency
from coin.exchange.liqui_v3.kr_rest.constants import currency_list


def from_native_currency(currency):
  assert currency.lower() == currency
  assert currency.upper() in currency_list, currency
  return currency.upper()


def to_native_currency(currency):
  assert currency.upper() == currency, currency
  assert currency in currency_list, currency
  return currency.lower()


class LiquiCurrency(NativeCurrency):
  _exchange = "Liqui"

  def __init__(self, currency, native_currency):
    assert currency.upper() == currency, (currency, native_currency)
    assert native_currency.lower() == native_currency, (currency, native_currency)
    assert to_native_currency(currency) == native_currency, (currency, native_currency)
    super().__init__(currency, native_currency)

  @classmethod
  def FromStrCurrencyImpl(cls, currency_str, current_datetime):
    return LiquiCurrency(currency_str, to_native_currency(currency_str))

  @classmethod
  def FromStrNativeCurrencyImpl(cls, native_currency_str, current_datetime):
    native_currency_str = native_currency_str.lower()
    return LiquiCurrency(from_native_currency(native_currency_str), native_currency_str)
